package com.xframe.xdal.core.model.es;

import com.xframe.xdal.core.model.ConditionValue;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.RangeQueryBuilder;

public class RangeQuery extends BaseQueryBuilder {
    /**
     * 构造函数
     *
     * @param esQueryBuildArgs 构造参数
     */
    public RangeQuery(String esQueryBuildArgs) {
        super(esQueryBuildArgs);
    }

    @Override
    public QueryBuilder builder(ConditionValue conditionValue) {
        RangeQueryBuilder queryBuilder = QueryBuilders.rangeQuery(conditionValue.getFieldName());
        switch (conditionValue.getOperators()){
            case GT:
                queryBuilder.gt(conditionValue.getValByEs());
                break;
            case GE:
                queryBuilder.gte(conditionValue.getValByEs());
                break;
            case LT:
                queryBuilder.lt(conditionValue.getValByEs());
                break;
            case LE:
                queryBuilder.lte(conditionValue.getValByEs());
                break;
            default:
                queryBuilder.gt(conditionValue.getValByEs());
                break;
        }
        return queryBuilder;
    }
}
